/*
* Copyright (c) 2025 Huawei Device Co., Ltd.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including but not limited to the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to provide persons with access to the Software
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGE OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

<template>
  <div class='home-header'>
    <MultiDiversionVue :direction='multiDiversionDirection'>
      <DiversionItemVue
        name='firstTitle'
        :diversionCols='tabBarCols'
        :diversionGap='barGap'
      >
        <div class='top-tab-bar'>
          <span class='top-tab-bar-text-selected'>华为</span>
          <span class='top-tab-bar-text'>AITO汽车</span>
          <span class='top-tab-bar-text'>华为智选</span>
          <span class='top-tab-bar-text'>生态周边</span>
        </div>
      </DiversionItemVue>
      <DiversionItemVue
        name='secondTitle'
        :diversionCols='searchBarCols'
        :diversionGap='barGap'
      >
        <div class='search-bar'>
          <input type='text' class='search-bar-input' placeholder='搜索...' />
          <img
            class='search-bar-image'
            src='../../assets/line_viewfinder.svg'
          />
          <img class='search-bar-image' src='../../assets/msg_big.png' />
        </div>
      </DiversionItemVue>
    </MultiDiversionVue>
  </div>
</template>

<script>
import {
  MultiDiversionVue,
  DiversionItemVue,
} from 'web-multidevice-advanced-vue2/src';
import { breakpointManager } from '../../utils/breakpointInit';

export default {
  name: 'PageHeader',
  components: {
    MultiDiversionVue,
    DiversionItemVue,
  },
  data() {
    return {
      multiDiversionDirection: 'vertical',
      tabBarCols: 7,
      searchBarCols: 5,
      barGap: 10,
      breakpointManager: null,
    };
  },
  mounted() {
    this.unsubscribe = breakpointManager.subscribeToBreakpoint(() => {
      this.multiDiversionDirection = breakpointManager.useBreakpointValue({
        xs: 'vertical',
        sm: 'vertical',
        md: 'horizontal',
        lg: 'horizontal',
        xl: 'horizontal',
      });

      this.tabBarCols = breakpointManager.useBreakpointValue({
        xs: 12,
        sm: 12,
        md: 7,
        lg: 8,
        xl: 8,
      });

      this.searchBarCols = breakpointManager.useBreakpointValue({
        xs: 12,
        sm: 12,
        md: 5,
        lg: 4,
        xl: 8,
      });
    });
  },
  beforeDestroy() {
    if (this.unsubscribe) {
      this.unsubscribe();
    }
  },
};
</script>

<style lang='less' scoped>
@import './index.less';
</style>
